package com.gem.sms.service.impl;

import com.gem.sms.entity.Student;
import com.gem.sms.mapper.StudentMapper;
import com.gem.sms.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    StudentMapper studentMapper;
    @Override
    public void addStu(Student student) {
        studentMapper.save(student);
    }

    @Override
    public Student getStudentByStuNo(String stuNo) {
        return studentMapper.getStudentByStuNo(stuNo);
    }

    @Override
    public Student canLogin(String sno, String pwd) {
        return studentMapper.canLogin(sno,pwd);
    }

    @Override
    public PageInfo<Student> listByPages(int pageNow, int pageSize, String searchName) {
        PageHelper.startPage(pageNow, pageSize, true);
        List<Student> students=null;
        if (searchName!=null)
        {
            students=studentMapper.selectStudentsByName(searchName);
        }else
        {
            students = studentMapper.selectAllStudents();
        }
        PageInfo<Student> pageInfo = new PageInfo<>(students);
        return pageInfo;
    }

    @Override
    public void updateStu(Student student) {
        studentMapper.update(student);
    }

    @Override
    public void delete(String stuNo) {
        studentMapper.delete(stuNo);
    }

    @Override
    public List<Student> list() {
        return studentMapper.selectAllStudents();
    }
}
